extends layout
block content
  +header("my")
  .container
    ul.posts
      each res in posts
        li
          .author
            span(title=res.name)
              a(href="/posts?author=" + res.name) author: #{res.name}
            span 评论数：#{res.comments}
            span 浏览量：#{res.pv}
          .comment_pv
            span #{res.moment}
          a(href="/posts/" + res.id)
            .title
              img.userAvator(src="images/" + res.avator + ".png")
              | #{res.title}
            .content.markdown!= res.content
    .pagination(style="margin-top: 30px" id="page")
append script
  script(src="/pagination.js")
  script.
    pagination({
      selector: '#page',
      totalPage: #{postsPageLength},
      currentPage: 1,
      prev: '上一页',
      next: '下一页',
      first: true,
      last: true,
      showTotalPage: true,
      count: 2//当前页前后显示的数量
    },function(val){
      // 当前页
      $.ajax({
        url: "posts/self/page",
        type: 'POST',
        data:{
          page: val,
          name: location.search.slice(1).split('=')[1]
        },
        cache: false,
        success: function (msg) {
          //console.log(msg)
          if (msg != 'error') {
            $('.posts').html(' ')
            $.each(msg,function(i,val){
              //console.log(val.content)
              $('.posts').append(
                '<li>'+
                '<div class=\"author\">'+
                '<span title=\"'+ val.name +'\"><a href=\"/posts?author='+ val.name +' \">author: '+ val.name +'</a></span>'+
                '<span>评论数：'+ val.comments +'</span>'+
                '<span>浏览量：'+ val.pv +'</span>'+
                '</div>'+
                '<div class=\"comment_pv\">'+
                '<span>'+ val.moment +'</span>'+
                '</div>'+
                '<a href=\"/posts/'+ val.id +'\">'+
                '<div class=\"title\">'+
                '<img class="userAvator" src="images/' + val.avator + '.png">' +
                val.title +
                '</div>'+
                '<div class=\"content\">'+
                val.content +
                '</div>'+
                '</a>'+
                '</li>'
              )
            })
          }else{
            alert('分页不存在')
          }
        }
      })
    })